package com.tjetc._2code_block;


import java.util.ArrayList;

class Sample {
    Sample(String s) {
        System.out.println(s);
    }

    Sample() {
        System.out.println("Sample 默认构造函数被调用");
    }
}

class Test {
    Sample sam1 = new Sample("sam1 成员初始化");
    static Sample sam = new Sample("静态成员 sam 初始化");

    static {
        System.out.println("static 块执行");
        if (sam == null) {
            System.out.println("sam is null");
        }
    }

    Test()//构造器
    {
        System.out.println("Test 默认构造函数被调用");
    }


    public static void main(String str[]) {
        /*
         结果：
             1.静态成员 sam 初始化
             2.static 块执行
             3.sam1 成员初始化
             4.Test 默认构造函数被调用
        */
        Test a = new Test();
    }
}


class Person {
    public static int total;

    static {//静态代码块
        total = 100;
        System.out.println("in static block!");
    }
}

public class _3CodeBlockExercise {

    public static void main(String[] args) {
        System.out.println("total = " + Person.total); // 100
        System.out.println("total = " + Person.total); // 100
    }
}
